package com.lokiy.kit.fragment

import android.os.Bundle
import android.view.View
import android.widget.SeekBar
import com.lokiy.core.fragment.ViewBindingFragment
import com.lokiy.kit.databinding.FragmentCornerBinding
import com.lokiy.annotation.FragmentInfo
import com.lokiy.kit.ext.setupToolbar

/**
 *
 * @author Lokiy
 * @date 2023-08-07 10:23
 */
@FragmentInfo("圆角控件")
class CornerFragment : ViewBindingFragment<FragmentCornerBinding>() {

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        setupToolbar(binding.toolbar)

        val listener = object : SeekBar.OnSeekBarChangeListener {
            override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
                when (seekBar) {
                    binding.topLeft -> binding.cornerLayout.topLeftRadius = progress * 2f
                    binding.topRight -> binding.cornerLayout.topRightRadius = progress * 2f
                    binding.bottomLeft -> binding.cornerLayout.bottomLeftRadius = progress * 2f
                    binding.bottomRight -> binding.cornerLayout.bottomRightRadius = progress * 2f
                }
            }

            override fun onStartTrackingTouch(seekBar: SeekBar?) {
            }

            override fun onStopTrackingTouch(seekBar: SeekBar?) {
            }
        }
        binding.topLeft.setOnSeekBarChangeListener(listener)
        binding.topRight.setOnSeekBarChangeListener(listener)
        binding.bottomLeft.setOnSeekBarChangeListener(listener)
        binding.bottomRight.setOnSeekBarChangeListener(listener)

        binding.topLeft.progress = 10
        binding.topRight.progress = 10
        binding.bottomLeft.progress = 10
        binding.bottomRight.progress = 10
    }
}